<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>清汀管理</title>
    <meta name="author" content="DeathGhost"/>
    <link rel="stylesheet" type="text/css" href="/admin/static/css/index.css"/>
    <script type="text/javascript" src="http://cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></script>
    <script src="/admin/static/js/Particleground.js"></script>
    <script src="/admin/static/js/hmac-sha256.js"></script>
    <script src="/admin/static/js/RSA/Barrett.js"></script>
    <script src="/admin/static/js/RSA/BigInt.js"></script>
    <script src="/admin/static/js/RSA/RSA.js"></script>
    <script src="/admin/static/js/gt.js"></script>
<!--    <script src="http://static.geetest.com/static/tools/gt.js"></script>-->
    <script type="text/javascript">
        var param = {};
//        var handler = function (captchaObj) {
//            captchaObj.appendTo("#captcha");
//            captchaObj.bindOn("#button");
//            captchaObj.onSuccess(function () {
//                $(".gt_popup_cross").click();
//                param = captchaObj.getValidate();
//                login();
//            });
//        };
//        $.ajax({
//            url: "/admin/gtCheck/StartCaptchaServlet.php?rand=" + Math.round(Math.random() * 100),
//            type: "get",
//            dataType: "json",
//            success: function (data) {
//                initGeetest({
//                    gt: data.gt,
//                    challenge: data.challenge,
//                    product: "popup", // 产品形式
//                    offline: !data.success
//                }, handler);
//            }
//        });
        $(function () {
            loadGt();
        });
        function loadGt() {
            $.get("/admin/gtCheck/StartCaptchaServlet.php?rand=" + (new Date()).getTime(), function (data) {
                var data = JSON.parse(data);
                var fig = {
                    gt: data.gt,
                    challenge: data.challenge,
                    new_captcha: data.new_captcha, // 用于宕机时表示是新验证码的宕机
                    offline: !data.success, // 表示用户后台检测极验服务器是否宕机，一般不需要关注
                    product: "bind",
                    width: "100%"
                };
                initGeetest(fig, function (captchaObj) {
                    captchaObj.appendTo("#button"); // 绑定位置
                    document.getElementById('button').addEventListener('click', function () {
                        captchaObj.verify();
                    });
                    captchaObj.onSuccess(function () {
                        param = captchaObj.getValidate();
                        login();
                    });
                });
            });
        }
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            //粒子背景特效
            $('body').particleground({
                dotColor: '#5CA0BC',
                lineColor: '#5CA0BC'
            });
            document.getElementById("name").onkeyup = function (event) {
                var e = event || window.event || arguments.callee.caller.arguments[0];
                if (e && e.keyCode == 13) { // enter 键
                    $("#password").focus();
                }
            };
            document.getElementById("password").onkeyup = function (event) {
                var e = event || window.event || arguments.callee.caller.arguments[0];
                if (e && e.keyCode == 13) { // enter 键
                    $("#button").click();
                }
            }
        });
        // 登录动画
        function login() {
            $(".admin_login").fadeOut(300);
            $(".doLogin").fadeIn(600);
            $('.doLogin').addClass('form-success');
            setTimeout(function () {
                sendInfo();
            }, 600);
        }
        // 发送登录请求
        function sendInfo() {
            console.log(param);
            param.info = rsa();
            $.post("/admin/login.php", param, function (data) {
                var res = JSON.parse(data).code;
                if (res == "000000") {
                    location.replace("/admin/view");
                    return;
                } else if (res == "100001") {
                    $("#name").addClass("invalid");
                    $("#name").attr("placeholder", "请填写帐号");
                } else if (res == "100002") {
                    $("#name").addClass("invalid");
                    $("#name").val("").attr("placeholder", "无此帐号，请重新输入");
                } else if (res == "100003") {
                    $("#password").addClass("invalid");
                    $("#password").val("").attr("placeholder", "您输入的密码有误，请重新输入");
                }
                console.log(data);
                // 撤回登录中状态
                $(".doLogin").fadeOut(500);
                $('.doLogin').removeClass('form-success');
                $(".admin_login").fadeIn(600);
            });
        }
        // 加密数据
        function rsa() {
            var rsa_n = 'A61CEDE5DBDCE9F466CCB9930FD33B2D471514159CAEA6FAE97CC13A0BCF0887A8636BE94614179374B01FD96705621B4CF4B82C01002A23FFB9C4D79B5C59EE8B6B7DB106BC9DD2218E86712E12CA2EC46170BBFBBB6C41F0619344D2A0253FAB8B650CD7D47F97B3D9E0AA313ED53BEACE5333EFFFB8CC18525A529B647AA3';
            var hmacPassword = CryptoJS.HmacSHA256($("#password").val(), "Qt16s1ZfE2A-2WpQ0epWwz-053C2K-BDnG7QaS-JepDs").toString();
            var info = hmacPassword + "-" + $("#name").val();
            setMaxDigits(131);
            var key = new RSAKeyPair("10001", '', rsa_n);
            return encryptedString(key, info);
        }
    </script>
</head>
<body>
<!--<div id="captcha"></div>-->
<dl class="admin_login">
    <dt>
        <strong>清汀管理系统</strong>
        <em>Management System</em>
    </dt>
    <dd class="user_icon">
        <input type="text" placeholder="账号" class="login_txtbx" id="name"/>
    </dd>
    <dd class="pwd_icon">
        <input type="password" placeholder="密码" class="login_txtbx" id="password"/>
    </dd>
    <dd>
        <input type="button" value="立即登陆" class="submit_btn" id="button"/>
    </dd>
    <dd><p>私人所有&nbsp;&nbsp;闲人勿入</p></dd>
</dl>
<div class="doLogin"><h1>正在校验 ...</h1></div>
</body>
</html>